//
//  ColorBackgroundView.m
//  MClient
//
//  Created by  史正烨 on 11-3-10.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ColorBackgroundView.h"
#import "MCUserDefaults.h"

@implementation ColorBackgroundView
@synthesize isOddLine;

- (id)initWithLineFlag:(BOOL)lineFlag {
	if (self = [super init]) {
        isOddLine = lineFlag;
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
	CGContextRef context = UIGraphicsGetCurrentContext();
	MCUserDefaults* defaults = [MCUserDefaults instance];
	UIColor* rectColor = isOddLine ? defaults.listViewCellRectColor_Odd : defaults.listViewCellRectColor_Even;
	
	CGContextSetFillColorWithColor(context, rectColor.CGColor);
	CGContextFillRect(context, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - 2));
	
	CGContextSetLineWidth(context, 1);
	CGContextSetStrokeColorWithColor(context, defaults.listViewCellLineColor.CGColor);
	CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + rect.size.height - 1.5);
	CGContextAddLineToPoint(context, rect.origin.x+rect.size.width, rect.origin.y + rect.size.height - 1.5);
	CGContextStrokePath(context);
	
	CGContextSetStrokeColorWithColor(context, defaults.listViewCellLineLowColor.CGColor);
	CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + rect.size.height - 0.5);
	CGContextAddLineToPoint(context, rect.origin.x+rect.size.width, rect.origin.y + rect.size.height - 0.5);
	CGContextStrokePath(context);
	
	//CGContextClosePath(context);
}


- (void)dealloc {
    [super dealloc];
}


@end
